package cn.itlight.controller;

import cn.itlight.entity.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {

    //需要配置成Bean
    @Autowired
    private RestTemplate restTemplate ;

    @HystrixCommand(fallbackMethod = "fallbackMethod")   //方法熔断
    @GetMapping("/order/{id}")
    public User getById(@PathVariable("id")Long id){
        String url = "http://user-server/user/"+id;

        //发送http请求
        return restTemplate.getForObject(url, User.class);

    }

    public User fallbackMethod(@PathVariable("id")Long id){
        return new User(-1L,"挂了","重新来哦");
    }
}
